package com.cloud.controller;

import com.cloud.dto.TeamDto;
import com.cloud.dto.UserDto;
import com.cloud.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@ResponseBody
@RestController
@RequestMapping("team")
public class TeamController {
    @Autowired
    TeamService teamService;

    //新建团队
    @PostMapping("/addteam")
    public Map addTeam(@RequestBody TeamDto teamDto){
        Map map=new HashMap();
        TeamDto teamDto1=teamService.addTeam(teamDto);
        map.put("newTeam",teamDto1);
        return map;
    }

    //根据团队id查找所有成员
    @GetMapping("/getmymember/{teamId}")
    public Map getMyMember(@PathVariable("teamId") Integer teamId) {
        Map map=new HashMap();
        List<UserDto> userDtoList=teamService.getMyMember(teamId);
        map.put("userDtoList",userDtoList);
        return map;
    }

    //根据团队id查找team
    @GetMapping("/getteambyid/{teamId}")
    public Map getTeamById(@PathVariable("teamId") Integer teamId){
        Map map=new HashMap();
        TeamDto teamDto=teamService.getTeamById(teamId);
        map.put("teamDtoById",teamDto);
        return map;
    }

    //根据团队名称查找团队
    @GetMapping("/getteambyname/{teamName}")
    public Map getTeamByName(@PathVariable("teamName") String teamName){
        Map map=new HashMap();
        TeamDto teamDto=teamService.getTeamByName(teamName);
        map.put("teamDtoByName",teamDto);
        return map;
    }

    //添加组长名字
//    @PostMapping("/addleadername")
//    public Map addLeader_name(@RequestBody List<TeamDto> teamDtoList){
//        Map map=new HashMap();
//        List<TeamDto> teamDtos=teamService.addLeader_name(teamDtoList);
//        map.put("teams",teamDtos);
//        return map;
//    }

    //查找所有团队
    @GetMapping("/allteams")
    public Map findAllTeams(){
        Map map=new HashMap();
        List<TeamDto> teamDtos=teamService.getAllTeam();
        map.put("allteams",teamDtos);
        return map;
    }

    }
